//
//  HomeViewController.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/2/27.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "HomeViewController.h"
#import "SearchForDiseaseForIpadVC.h"
#import "SearchForDiseaseForIphoneVC.h"
#import "MainTainNotificationVC.h"
#import "MainTainNotificationForIPadVC.h"
#import "DiseaseForMaintainForIpadVC.h"
#import "DiseaseForMaintainForIphoneVC.h"
#import "TestForNotificationForIPhoneVC.h"
#import "TestForNotificationForIpadVC.h"
#import "DiseaseCAndRForIPhoneVC.h"
#import "DiseaseCAndRForIpadVC.h"
#import "CheckSafetyForIpadVC.h"
#import "CheckSafeForIphoneVC.h"
#import "LoginViewController.h"
#import "HomeTableViewCell.h"
#import "UserInfoViewController.h"
#import "SettingViewController.h"
#import "PublicForIpadViewController.h"
#import "PublicForIphoneViewController.h"
#import "HomeCollectionViewCell.h"
#import "HomeCycleTableViewCell.h"
#define HomeTableViewCellID @"cellid1"
#define HomeCollectionCellID @"cellid2"
#define HomeCycleCellID @"cellid3"
@interface HomeViewController ()<UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIAlertViewDelegate>
@property (nonatomic,strong) UITableView *cycleTableView;
@property (nonatomic,strong) NSMutableArray *cycleRootArray;
@property (nonatomic,strong) NSMutableArray  *cycleChangedArray;
@property (nonatomic,strong) NSMutableArray *todoArray;
@property (nonatomic,strong) UICollectionView *collection;
@property (nonatomic,strong) UIView *messageView;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSInteger offset;
@property (nonatomic,strong) NSDictionary *stateDic;
@property (nonatomic,strong) NSArray *imgArray;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *huiImgArray;
@property(nonatomic,strong) NSString* trackviewUrl;//下载APP链接
@end

@implementation HomeViewController
#pragma mark - Life cycle
- (void)viewWillAppear:(BOOL)animated{
    
        [self setWebData];
    [super viewWillAppear:animated];
}

#pragma mark 新版本检查
-(void)getNewversion{
    
    __weak typeof(self) weakSelf = self;
    [NetWorkTool getNewVerson:^(id data) {
        if (data) {
            if ([data[@"results"] count]==0) {
                
            }else{
            NSArray *resultsarray = [data objectForKey:@"results"];
            
            NSDictionary *inforDic = [resultsarray objectAtIndex:0];
            NSString*lastVersion;//上个版本
            
            NSString*trackName;
            NSString*currentVersion;//当前版本
            lastVersion = [inforDic objectForKey:@"version"];
            _trackviewUrl = [inforDic objectForKey:@"trackViewUrl"];//地址trackViewUrl
            
            trackName = [inforDic objectForKey:@"trackName"];//trackName
            NSDictionary *infoDict = [[NSBundle mainBundle]infoDictionary];
            
            currentVersion=[infoDict objectForKey:@"CFBundleShortVersionString"];
            
            
            NSArray *lastArray = [lastVersion componentsSeparatedByString:@"."];
            NSArray *currenArray =[currentVersion componentsSeparatedByString:@"."];
            //判断是否要更新
            
            if ([currenArray[0]intValue]<[lastArray[0]intValue]) {
                //更新
                [weakSelf getnewInfordescription:trackName];
            }else if([currenArray[0]intValue]==[lastArray[0]intValue]){
                if ([currenArray[1]intValue]<[lastArray[1]intValue]) {
                    //更新
                    [weakSelf getnewInfordescription:trackName];
                }else if([currenArray[1]intValue]==[lastArray[1]intValue]){
                    if ([currenArray[2]intValue]<[lastArray[2]intValue]){
                        //更新
                        [weakSelf getnewInfordescription:trackName];
                    }
                }
            }
            }
            
        }else{
            //  [MBProgressHUD showTextHUDAddedTo:self.view  Msg:@"获取不到版本号" animated:YES];
        }
        
    }];
    
    
}

-(void)getnewInfordescription:(NSString*)trackName{
    
    UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"更新" message:@"有新版本更新，为不影响正常使用请前往更新APP" delegate:self cancelButtonTitle:nil otherButtonTitles:@"更新", nil];
    alert.tag=100;
    [alert show];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpNav1];
    [self.tableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:HomeTableViewCellID];
    _imgArray = @[@"virus_patrol",@"repair_message",@"disease_repair",@"secure_check",@"check_announce",@"disease_check_receive",@"announcement",@"personal_information",@"setting"];
    _huiImgArray = @[@"g_virus_patrol",@"g_repair_message",@"g_disease_repair",@"g_secure_check",@"g_check_announce",@"g_disease_check_receive"];
    _titleArray = @[@"病害巡查",@"维修通知",@"维修记录",@"安全检查",@"验收通知",@"养护验收",@"公告",@"个人信息",@"设置"];
    if (IsPad) {
        
    }else{
        [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(64);
            make.bottom.mas_equalTo(0);
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
        }];
      //  [self setUpCycleTableView];
    }
    [self setUpTableViewFooterViewWithCollection];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getNewversion) name:@"NewVersion" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setWebData) name:@"homeReload" object:nil];
}

#pragma mark - Property
- (NSMutableArray *)cycleRootArray{
    if (_cycleRootArray == nil) {
        _cycleRootArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _cycleRootArray;
}
- (NSMutableArray *)cycleChangedArray{
    if (_cycleChangedArray==nil) {
        _cycleChangedArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _cycleChangedArray;
}
- (NSMutableArray *)todoArray{
    if (_todoArray==nil) {
        _todoArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _todoArray;
}
#pragma mark - UI
- (void)setUpNav1{
        self.navigationController.navigationBarHidden = YES;
        self.myTitle.text = @"中咨巡检通";
        self.myTitle.textColor = Bai_Color;
        self.nav.backgroundColor = MAIN_Color;
      // [self setRightBtnImg:[UIImage imageNamed:@"message"]];
      // [self setRightBtnTitle:@"退出"];
       self.navigationController.edgesForExtendedLayout=UIRectEdgeNone;

}
- (void)setUpCycleTableView{
    self.messageView = [[UIView alloc]init];
    self.messageView.backgroundColor = MAIN_Color;
    [self.view addSubview:self.messageView];
    [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(64);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    
    UIView *blackView = [[UIView alloc]init];
    blackView.backgroundColor = [PublicMethod colorWithHexString:@"#000000" andAlpha:0.7];
    [self.messageView addSubview:blackView];
    [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    
    UIImageView *img = [[UIImageView alloc]init];
    img.image = [UIImage imageNamed:@"img_notification"];
    [self.messageView addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(7);
        make.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(15, 16));
    }];
    
    [self.cycleRootArray addObjectsFromArray:@[@"关于十三五规划的相关通知，应当如何调整。十三五规划的相关通知，应当如何调整。",@"五规划的相关通知，应当如何调整。十三五规划的相关通知，应当如何调整。",@"关于十三五规划的相调整。十三五规划的相关通知，应当如何调整。"]];
    for (int i=0; i<20; i++) {
        [self.cycleChangedArray addObjectsFromArray:self.cycleRootArray];
    }
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"更多" forState:UIControlStateNormal];
    [btn setTitleColor:Bai_Color forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:ZitiRate*13];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [btn addTarget:self action:@selector(messageMoreClick) forControlEvents:UIControlEventTouchUpInside];
    [blackView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(40*WidthRate);
        make.right.mas_equalTo(-15*WidthRate);
    }];
    
    
    self.cycleTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.cycleTableView.delegate = self;
    self.cycleTableView.dataSource = self;
    self.cycleTableView.backgroundColor = Clear_Color;
    self.cycleTableView.scrollsToTop = NO;
    self.cycleTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.cycleTableView.showsVerticalScrollIndicator = NO;
    self.cycleTableView.scrollEnabled = NO;
    [self.cycleTableView registerClass:[HomeCycleTableViewCell class] forCellReuseIdentifier:HomeCycleCellID];
    [blackView addSubview:self.cycleTableView];
    [self.cycleTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(32);
        make.right.mas_equalTo(-55*WidthRate);
    }];
    [self setUpTimer];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = Bai_Color;
    [blackView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(0.5);
        make.right.mas_equalTo(-55*WidthRate);
    }];
}
#pragma mark - UI Response
- (void)rightButtonClick{
    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"消息模块即将上线" animated:YES];
}
- (void)messageMoreClick{
    
}
- (void)setUpTimer{
    if (self.timer) {
        [self.timer invalidate];
        self.timer = nil;
    }
    self.timer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(move) userInfo:@"" repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)move{
    
    [UIView animateWithDuration:1 animations:^{
        self.offset = self.offset + 30;
        if (self.offset == 30*self.cycleChangedArray.count) {
            self.offset = 0;
        }
        self.cycleTableView.contentOffset = CGPointMake(0, self.offset);
        
    }];
}
- (void)setUpTableViewFooterViewWithCollection{
    UICollectionViewFlowLayout *fl = [[UICollectionViewFlowLayout alloc]init];
    [fl setScrollDirection:UICollectionViewScrollDirectionVertical];
    fl.minimumInteritemSpacing = 0;//垂直间距
    fl.minimumLineSpacing= 0;//水平间距
    if (IsPad) {
      fl.itemSize = CGSizeMake(IPHONE_W/3, (IPHONE_H-64)/3);
      self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H-64) collectionViewLayout:fl];
        
    }else{
      fl.itemSize = CGSizeMake(IPHONE_W/3, (IPHONE_H-64)/3);
      self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H-64) collectionViewLayout:fl];
    }
    fl.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    self.collection.backgroundColor = Bai_Color;
    [self.collection registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:HomeCollectionCellID];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.showsVerticalScrollIndicator = NO;
    self.collection.showsHorizontalScrollIndicator = NO;
    self.tableView.tableFooterView = self.collection;

}

#pragma mark - Data handle
- (void)setWebData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetWorkTool getHomeData:^(id data) {
    [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
    if (data) {
        if ([data[@"success"] integerValue]) {
            self.stateDic = data[@"data"];
            [self.todoArray removeAllObjects];
            if ([data[@"data"][@"NoticeList"] count]<=3) {
                [self.todoArray addObjectsFromArray:data[@"data"][@"NoticeList"]];
            }else{
            for (int i =0; i<3; i++) {
                [self.todoArray addObject:data[@"data"][@"NoticeList"][i]];
            }
            }
            [self.collection reloadData];
            [self.tableView reloadData];
            [self.cycleTableView reloadData];
        }else{
            if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
            }else{
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
            }
        }
    }else{
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
    }
}];
}
- (void)gotoLogin{
    [PublicMethod noTokenToLoginWithNav:self.navigationController];
}
#pragma mark - Delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.cycleTableView]) {
        return 30;
    }else{
        return 120*HeightRate;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if ([tableView isEqual:self.cycleTableView]) {
        return self.cycleChangedArray.count;
    }else{
        return 0;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.cycleTableView]) {
        HomeCycleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeCycleCellID];
        cell.titleLab.text = self.cycleChangedArray[indexPath.row];
        return cell;
    }else{
        HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeTableViewCellID];
        [cell addValueWithTodoArray:self.todoArray MessageArray:@[@"4",@"5",@"6"]];
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.cycleTableView]) {
        
    }
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HomeCollectionCellID forIndexPath:indexPath];
    cell.contentView.backgroundColor = Bai_Color;
    if (indexPath.row == 1) {
        if ([self.stateDic[@"MaintentanceNoticeCnt"] integerValue]==0) {
            cell.badgeLab.hidden = YES;
        }else if([self.stateDic[@"MaintentanceNoticeCnt"] integerValue]>9){
            
            cell.badgeLab.hidden = NO;
            cell.badgeLab.text = @"9+";
        }else{
            cell.badgeLab.hidden = NO;
            cell.badgeLab.text = [NSString stringWithFormat:@"%@",self.stateDic[@"MaintentanceNoticeCnt"]];
        }
        [cell maintainNotiFrame];
    }else if(indexPath.row == 4){
        if ([self.stateDic[@"AcceptanceNoticeCnt"] integerValue]==0) {
            cell.badgeLab.hidden = YES;
        }else if([self.stateDic[@"AcceptanceNoticeCnt"] integerValue]>9){
            
            cell.badgeLab.hidden = NO;
            cell.badgeLab.text = @"9+";
        }else{
            cell.badgeLab.hidden = NO;
            cell.badgeLab.text = [NSString stringWithFormat:@"%@",self.stateDic[@"AcceptanceNoticeCnt"]];
        }
        [cell diseaseGetFrame];
    }else{
        cell.badgeLab.hidden = YES;
    }
    switch (indexPath.row) {
        case 0:{
            if ([self.stateDic[@"DamageInspection"] integerValue]) {
                cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
            }else{
                 cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        case 1:{
            if ([self.stateDic[@"MaintentanceNotice"] integerValue]) {
                cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
                
            }else{
               cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.badgeLab.hidden = YES;
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        case 2:{
            if ([self.stateDic[@"MaintentanceRecord"] integerValue]) {
                 cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
            }else{
                 cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        case 3:{
            if ([self.stateDic[@"SecurityCheck"] integerValue]) {
                 cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
            }else{
               cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        case 4:{
            if ([self.stateDic[@"AcceptanceNotice"] integerValue]) {
                 cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
            }else{
               cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.badgeLab.hidden = YES;
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        case 5:{
            if ([self.stateDic[@"MaintentanceAcceptance"] integerValue]) {
                 cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
                cell.title.textColor = Black_Color;
            }else{
                 cell.img.image = [UIImage imageNamed:self.huiImgArray[indexPath.row]];
                cell.title.textColor = [PublicMethod colorWithHexString:@"#d0d0d0" andAlpha:1];
            }
        }
            break;
        default:{
            cell.title.textColor = Black_Color;
            cell.img.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
        }
            break;
    }
   
    cell.title.text = self.titleArray[indexPath.row];
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (IsPad) {
        switch (indexPath.row) {
            case 0:
            {
                if ([self.stateDic[@"DamageInspection"] integerValue]) {
                    SearchForDiseaseForIpadVC *con = [[SearchForDiseaseForIpadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 1:
            {
                
                if ([self.stateDic[@"MaintentanceNotice"] integerValue]) {
                    MainTainNotificationForIPadVC *con = [[MainTainNotificationForIPadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 2:
            {
                
                if ([self.stateDic[@"MaintentanceRecord"] integerValue]) {
                    DiseaseForMaintainForIpadVC*con = [[DiseaseForMaintainForIpadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }

            }
                break;
            case 3:
            {
                if ([self.stateDic[@"SecurityCheck"] integerValue]) {
                
                    CheckSafetyForIpadVC *con = [[ CheckSafetyForIpadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 4:
            {
               
                if ([self.stateDic[@"AcceptanceNotice"] integerValue]) {
                
                    TestForNotificationForIpadVC *con = [[TestForNotificationForIpadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 5:
            {
                
                if ([self.stateDic[@"MaintentanceAcceptance"] integerValue]) {
                
                    DiseaseCAndRForIpadVC *con = [[DiseaseCAndRForIpadVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 6:
            {
                PublicForIpadViewController *con = [[PublicForIpadViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
            case 7:
            {
                UserInfoViewController *con = [[UserInfoViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
            default:
            {
                SettingViewController *con = [[SettingViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
        }
        
    }else{
        switch (indexPath.row) {
            case 0:
            {
                if ([self.stateDic[@"DamageInspection"] integerValue]) {
                    SearchForDiseaseForIphoneVC *con = [[SearchForDiseaseForIphoneVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 1:
            {
              if ([self.stateDic[@"MaintentanceNotice"] integerValue]) {
                    MainTainNotificationVC *con = [[MainTainNotificationVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 2:
            {
                
                if ([self.stateDic[@"MaintentanceRecord"] integerValue]) {
                    DiseaseForMaintainForIphoneVC *con = [[DiseaseForMaintainForIphoneVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
                
            }
                break;
            case 3:
            {
                if ([self.stateDic[@"SecurityCheck"] integerValue]) {
                
                    CheckSafeForIphoneVC *con = [[CheckSafeForIphoneVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 4:
            {
                
                if ([self.stateDic[@"AcceptanceNotice"] integerValue]) {
                    
                    TestForNotificationForIPhoneVC *con = [[TestForNotificationForIPhoneVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 5:
            {
                
                if ([self.stateDic[@"MaintentanceAcceptance"] integerValue]) {
                
                    DiseaseCAndRForIPhoneVC *con = [[DiseaseCAndRForIPhoneVC alloc]init];
                    [self.navigationController pushViewController:con animated:YES];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"暂时没有该功能权限！" animated:YES];
                }
            }
                break;
            case 6:
            {
                PublicForIphoneViewController *con = [[PublicForIphoneViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
            case 7:
            {
                UserInfoViewController *con = [[UserInfoViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
            default:
            {
                SettingViewController *con = [[SettingViewController alloc]init];
                [self.navigationController pushViewController:con animated:YES];
            }
                break;
        }
       
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex==0) {
        if (alertView.tag==100) {
            
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:_trackviewUrl]];
            
        }
    }
}
@end
